package framework.entity;

import java.util.ArrayList;
import java.util.StringTokenizer;


public class ACLInterface extends ACLEntity{


	public static String ACL_INTERFACE = "ACLINTERFACE";
	
	private String name;
	private ArrayList<ACLFunction> functions;

	
	public ACLInterface(){
		super("");
	}
	
	
	public ACLInterface(String n) {
		super(n);
		functions = new ArrayList<ACLFunction>();
	}

	public ACLInterface(String n, ArrayList<ACLFunction> list) {
		super(n);
		if (list == null)
			functions = new ArrayList<ACLFunction>();
		else
			functions = list;
		
	}

	// nom_interface{ nom_fonction( ar1 ar2 ar3): ar4 , ... }
	public ACLInterface(String str, int mode) {
		super(str.substring(0, str.indexOf('{')));
		functions = new ArrayList<ACLFunction>();
		
		StringTokenizer tok = new StringTokenizer(str, ",");
		tok.nextToken();
		while (tok.countTokens() > 1) {
			String op = tok.nextToken();
			addOperation(new ACLFunction(op, ACLFunction.MODE2));
		}
	}


	public void addOperation(ACLFunction op) {
		functions.add(op);
	}

	public String toString() {
		String result = getName() + "{,";
		for (int i = 0; i < functions.size(); i++) {
			result = result + functions.get(i).toString();
			result = result + ",";
		}
		result = result + "}";
		return result;
	}

	

	

	public ArrayList<ACLFunction> getFunctions() {
		return functions;
	}

	public void setFunctions(ArrayList<ACLFunction> array_operation) {
		this.functions = array_operation;
	}


	@Override
	public String getType() {
		// TODO Auto-generated method stub
		return ACL_INTERFACE;
	}
	
}
